﻿using System;
using System.Windows;
using System.Windows.Data;

namespace Notoric.View.Music.CWNotation.Converters
{
    /// <summary>
    /// Converts a boolean visibility flag to <see cref="Visibility"/> enumeration value and back.
    /// </summary>
    [ValueConversion(typeof(bool), typeof(Visibility))]
    public class VisibilityConverter : IValueConverter
    {
        #region IValueConverter Members

        /// <inheritdoc/>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var visible = (bool)value;

            if (visible)
                return Visibility.Visible;
            else
                return Visibility.Collapsed;
        }

        /// <inheritdoc/>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var visibility = (Visibility)value;

            if (visibility == Visibility.Visible)
                return true;
            else
                return false;
        }

        #endregion
    }
}
